<template>
    <div>
        <el-tree :props="props" :load="loadNode" lazy @current-change="currentChange">
        </el-tree>
    </div>
</template>

<script setup>
import { selectItemCategoryByParentId } from '@/utils/api/product.js'
import { onMounted, reactive } from 'vue';
const emit =defineEmits(['getTreeData'])
onMounted(() => {
    loadNode()
})
const props = reactive({
    label: 'name',
    children: 'zones',
    isLeaf: 'leaf'
})
const loadNode = async (node, resolve) => {
    // console.log(node,'树的结点');
    if (node?.level === 0) {
        let res = await selectItemCategoryByParentId()
        // console.log(res.data.result,22);
        if (res.data.status == 200) {
            return resolve(res.data.result)
        } else {
            return resolve([])
        }
    }
    if (node?.level >= 1) {
        let res = await selectItemCategoryByParentId({ type: node.data.cid })
        if (res.data.status == 200) {
            return resolve(res.data.result)
        } else {
            return resolve([])
        }
    }
}
const currentChange = (data) => {
  emit('getTreeData',data)
}


</script>
<style lang="scss" scoped></style>